package util
{
	import flash.text.TextFormat;
	
	import enums.main.UISize;
	
	import feathers.controls.Button;
	import feathers.controls.renderers.DefaultListItemRenderer;
	
	import model.vo.ItemVo;
	
	import starling.display.Image;
	import starling.utils.Color;
	
	/**
	 * 道具util
	 * @author £iang
	 * 
	 */	
	public class ItemUtil
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 将object转换为 ItemVo类型
		 * @param obj Object类型
		 * @return ItemVo
		 * 
		 */		
		public static function mapObj2ItemVo( obj:Object ):ItemVo
		{
			var itemVo:ItemVo = new ItemVo();
			
			itemVo.itemId = obj.id;
			itemVo.ch = obj.ch;
			itemVo.jp = obj.jp;
			itemVo.iconId = obj.iconId;
			itemVo.ps = obj.ps;
			
			return itemVo;
		}
		
		/**
		 * 通用item皮肤 
		 * @return 
		 * 
		 */		
		public static function commonItem():DefaultListItemRenderer
		{
			var renderer:DefaultListItemRenderer = new DefaultListItemRenderer();
			renderer.width = UISize.DPI_SCALE * UISize.ITEM_LIST_ITEM_W;
			renderer.height = UISize.ITEM_LIST_ITEM_H * UISize.DPI_SCALE;
			renderer.defaultLabelProperties.textFormat = new TextFormat( "微软雅黑,宋体", 24 * UISize.DPI_SCALE, 
				Color.WHITE, false );
			renderer.horizontalAlign = Button.HORIZONTAL_ALIGN_LEFT;
			renderer.verticalAlign = Button.VERTICAL_ALIGN_MIDDLE;
			renderer.itemHasAccessory = false;
			renderer.gap = 0;
			renderer.defaultLabelProperties.wordWrap = true;
			return renderer;
		}
		
		/**
		 * 通用只含文本的item皮肤 
		 * @return 
		 * 
		 */
		public static function commonSimpleItem( column:int, gap:Number ):DefaultListItemRenderer
		{
			var renderer:DefaultListItemRenderer = new DefaultListItemRenderer();
			renderer.width = ( UISize.MAIN_W - UISize.DPI_SCALE * ( 20 + gap ) ) / column;
			renderer.height = UISize.ITEM_LIST_ITEM_H * UISize.DPI_SCALE;
			renderer.defaultLabelProperties.textFormat = new TextFormat( "微软雅黑,宋体", 24 * UISize.DPI_SCALE, 
				Color.WHITE, false );
			renderer.horizontalAlign = Button.HORIZONTAL_ALIGN_LEFT;
			renderer.verticalAlign = Button.VERTICAL_ALIGN_MIDDLE;
			renderer.itemHasAccessory = false;
			renderer.itemHasIcon = false;
			renderer.gap = 0;
			renderer.defaultLabelProperties.wordWrap = true;
			renderer.defaultLabelProperties.isHTML = true;
			return renderer;
		}
		
		
		/**
		 * 将itemVo转换为列表用object 
		 * @param itemVo itemVo
		 * @return object 
		 * 
		 */		
		public static function mapItemVo2ListObj( itemVo:ItemVo, num:int = 0 ):Object
		{
			var tmpObj:Object = new Object();
			var tmpImage:Image;
			var labelStr:String = itemVo.jp;
			
			if ( num > 0 )
				labelStr = itemVo.jp + "×" + num + "　";
			tmpObj.label = labelStr;
			tmpImage = new Image(  AtlasTextureGenerator.getItemTextureById( 
				itemVo.iconId
			) );
			tmpImage.scaleX = tmpImage.scaleY = UISize.DPI_SCALE;
			tmpObj.icon = tmpImage;
			tmpObj.itemId = itemVo.itemId;
			return tmpObj;
		}
		
		/**
		 * 将文本转换为列表用object 
		 * @param str 文本
		 * @return object 
		 * 
		 */		
		public static function mapText2ListObj( str:String ):Object
		{
			var tmpObj:Object = new Object();
			
			tmpObj.label = str;
			return tmpObj;
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function ItemUtil()
		{
		}
	}
}